/*
 *  $Id: TwilightHarbringers.cs 1016 2010-05-12 11:24:26Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Spells {
    public class TwilightHarbringers: SpellCard {
        public TwilightHarbringers(): base("001_d_s_twilight_harbringers") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Darkness;
            Value = 100;
            Target = JogTarget.Use;
            AddCondition(new MeditationCondition(2, true));
        }

        private static int GetManaCost(Player player) {
            return player.GetCreatureCount() + player.Enemy.GetCreatureCount();
        }

        public override bool IsPossibleAction(TargetArgs args) {
            int cost = GetManaCost(args.Player);
            if (cost > args.Player.GetMana(ElementType.Darkness)) {
                args.Player.Game.ErrorNotice(ManaCondition.NotEnough.GetText(ElementType.Darkness));
                return false;
            }
            return true;
        }

        public override void DoAction(TargetArgs args) {
            int cost = GetManaCost(args.Player);
            args.Player.DecrementMana(ElementType.Darkness, cost);
            foreach (Player owner in args.Players) {
                foreach (Creature cr in owner.GetCreatures()) {
                    int damage = cr.HealthToMax;
                    if (damage > 0) cr.DamageBy(NewDamage(args, DamageType.PhysicalAttack, damage));
                }
            }
        }
    }
}
